<?php
namespace BoxPay\Controller;
use Think\Controller;

class CommonController extends \HomeController {
	public function _initialize() {
		parent::_initialize();

	}

	/****display模板***/
	public function display($dir) {
		if (!is_file($dir)) {
			$templateFile = $this->getTemplateFile("Order/home");
			$this->page_content = self::fetch($dir);
			if (IS_AJAX || I('requestFrom') == 'modal') {
				echo $this->page_content;
			} else {
				parent::display($templateFile);
			}
		} else {
			parent::display($dir);
		}
	}

	public function getTemplateFile($templateFile) {

		//dump( $this->is_mobile);
		$tpl = BOX_MODULE_NAME;
		if ($this->is_mobile) {
			$tpl = "Wap";
		}
		if (!checkAgent()) {
			$tpl = "Wap";
		}
		C('DEFAULT_V_LAYER', "View/" . $tpl);
		if ($templateFile == "" || !is_file($templateFile)) {
			$depr = C('TMPL_FILE_DEPR');
			if (!$templateFile) {
				$templateFile = CONTROLLER_NAME . $depr . ACTION_NAME;
			}
		}
		$File = "./Apps/" . C('DEFAULT_MODULE') . "/View/" . $tpl . "/" . $templateFile . C('TMPL_TEMPLATE_SUFFIX');
		if ($tpl != "Home" && is_file($File)) {
			return $File;
		} else {
			return "./Apps/" . C('DEFAULT_MODULE') . "/View/" . $templateFile . C('TMPL_TEMPLATE_SUFFIX');
		}

	}

	/****fetch模板***/
	public function fetch($templateFile, $content = '', $prefix = '') {
		$templateFile = $this->getTemplateFile($templateFile);
		//dump($templateFile);
		return parent::fetch($templateFile, $content, $prefix);
	}

}